<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<input type="button" id="btn01" value="开启定时器" />
		<p>点击上面按钮，每隔3秒钟，会连续执行多次定时任务</p>
		<input type="button" id="btn02" value="关闭定时器" />
		<p>点击上面的按钮，关闭定时任务</p>
	</body>
	<script type="text/javascript">
		// 开启定时任务
		var oBtn01 = document.getElementById("btn01")
		// 关闭定时
		var oBtn02 = document.getElementById("btn02")
		var t = null;
		oBtn01.onclick = function(){
			t = setInterval(function(){
				// 每隔三秒就会调用一次
				alert('炸了')
			},3000)
		}
		oBtn02.onclick = function(){
			// 关闭
			clearInterval(t)
		}
	</script>
</html>
